class main {
    public int firstMissingPositive(int[] nums) {
        Arrays.sort(nums);
        int ref = 1;
        int prev = nums[0] - 1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 0) {
                if (nums[i] != prev && nums[i] == ref) {
                    ref++;
                    prev = nums[i];
                }
            }
        }
        return ref;
    }
}